class Matrix():
    def __init__(self, mtrx: list) -> None:
        self.mtrx = mtrx
        self.transpose(self.mtrx)

    def transpose(self, matrix: list) -> list:
        mtrx_new = [[0 for _  in range(len(self.mtrx))] for _1 in range(len(self.mtrx[0]))]
        for i in range(len(self.mtrx)):
            for j in range(len(self.mtrx[0])):
                mtrx_new[j][i] =  self.mtrx[i][j]
        if (self.mtrx == [[]]):
            return [[]]
        return mtrx_new

    def size(self) -> tuple:
        list_len = []
        if len(self.mtrx):
            if isinstance(self.mtrx, type) or isinstance(self.mtrx, list):
                list_len.append(len(self.mtrx))
                list_len.append(len(self.mtrx[0]))
                return tuple(list_len) 
            else:
                list_len.append(len(self.mtrx))
                return tuple(list_len)
        return tuple(list_len)
    
    def __str__(self) -> str:
        res = []
        rc, cc = self.size()
        for i in range(rc):
            res.append("\t".join(str(x) for x in self.mtrx[i]))
        str_result = "\n".join(res)
        print(str_result)
        return str_result

    def __add__(self, other) -> list:
        row_len, col_len = self.size()
        row1_len, col1_len = other.size()
        result = [[self.mtrx[i][j] + other.mtrx[i][j]  for j in range(col1_len)] for i in range(row_len)]
        print(result)
        return Matrix(result)

    def __iadd__(self, other) -> list:
        row_len, col_len = self.size()
        row1_len, col1_len = other.size()
        result = [[self.mtrx[i][j] + other.mtrx[i][j]  for j in range(col1_len)] for i in range(row_len)]
        self.mtrx = result[:]
        print(self.mtrx)
        return Matrix(self.mtrx)

list_of_lists_1 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
list_of_lists_2 = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]
mtrx_1 = Matrix(list_of_lists_1)
mtrx_2 = Matrix(list_of_lists_2)
assert (mtrx_1 + mtrx_2).__str__() == '''10 10  10\n10  10  10\n10  10  10'''

list_of_lists_1 = [[31, 86, 12, 48], [64, 14, 43, 17], [63, 62, 55, 53], [39, 69, 66, 13]]
list_of_lists_2 = [[93, 23, 86, 97], [35, 3, 92, 73], [57, 43, 36, 6], [27, 63, 33, 35]]
mtrx_1 = Matrix(list_of_lists_1)
mtrx_2 = Matrix(list_of_lists_2)
assert (mtrx_1 + mtrx_2).__str__() == '''124    109 98	145
99	17	135	90
120	105	91	59
66	132	99	48'''

list_of_lists_1 = [[56, 37, 12, 53, 84], [15, 76, 18, 90, 95], [64, 1, 100, 56, 17],
                   [60, 81, 23, 21, 74], [9, 43, 100, 70, 67], [84, 41, 63, 54, 16]]

list_of_lists_2 = [[77, 62, 17, 58, 8], [96, 85, 49, 47, 51], [81, 58, 99, 5, 47],
                   [91, 7, 14, 61, 20], [4, 87, 47, 48, 76], [68, 23, 91, 79, 39]]
mtrx_1 = Matrix(list_of_lists_1)
mtrx_2 = Matrix(list_of_lists_2)
assert (mtrx_1 + mtrx_2).__str__() == '''133	99	29	111	92
111	161	67	137	146
145	59	199	61	64
151	88	37	82	94
13	130	147	118	143
152	64	154	133	55'''

list_of_lists_1 = [[49, 41, 17, 3, 100, 17, 93, 65, 56], [35, 62, 79, 68, 91, 11, 61, 23, 63],
                   [40, 57, 3, 43, 89, 76, 92, 62, 42], [98, 91, 33, 92, 4, 86, 45, 95, 99],
                   [25, 43, 31, 38, 44, 31, 48, 70, 30], [72, 84, 93, 52, 76, 35, 74, 16, 79],
                   [68, 96, 27, 53, 23, 59, 5, 46, 93], [46, 3, 31, 17, 33, 80, 16, 85, 31],
                   [63, 7, 66, 34, 5, 94, 49, 28, 47], [33, 87, 88, 98, 92, 39, 64, 34, 16]]

list_of_lists_2 = [[81, 37, 86, 12, 79, 60, 26, 61, 11], [9, 2, 22, 86, 29, 100, 5, 30, 29],
                   [45, 91, 8, 54, 3, 52, 20, 40, 98], [60, 86, 78, 48, 66, 99, 23, 67, 72],
                   [69, 21, 92, 70, 25, 64, 28, 68, 2], [22, 90, 70, 90, 30, 77, 81, 17, 7],
                   [11, 23, 3, 16, 5, 80, 45, 99, 18], [32, 48, 78, 75, 59, 33, 14, 17, 6],
                   [58, 19, 52, 89, 22, 75, 58, 95, 78], [39, 2, 90, 74, 47, 21, 21, 13, 95]]
mtrx_1 = Matrix(list_of_lists_1)
mtrx_2 = Matrix(list_of_lists_2)
assert (mtrx_1 + mtrx_2).__str__() == '''130	78	103	15	179	77	119	126	67
44	64	101	154	120	111	66	53	92
85	148	11	97	92	128	112	102	140
158	177	111	140	70	185	68	162	171
94	64	123	108	69	95	76	138	32
94	174	163	142	106	112	155	33	86
79	119	30	69	28	139	50	145	111
78	51	109	92	92	113	30	102	37
121	26	118	123	27	169	107	123	125
72	89	178	172	139	60	85	47	111'''
